﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _05月10日作业
{
    class Program
    {
        static void Main(string[] args)
        {

            Tast5();
        }

       
        static void square()
        {
            Console.WriteLine("请输入正方形的边长！");
            int sideLength = Convert.ToInt32(Console.ReadLine());

            string[,] arr= new string[sideLength,sideLength];

            for (int i = 0; i < sideLength; i++)
            {
                for (int j = 0; j < sideLength; j++)
                {
                    arr[i,j] = "*";
                }

            }
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    Console.Write(arr[i, j]+" ");
                }
                Console.WriteLine(" ");
            }

        }
        static void MultiplicationTable()
        {
            string[,] table = new string[9, 9];
            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < 9; j++)
                {
                    table[i, j]=(i+1)+"*"+(j+1)+"="+(i+1)*(j+1);
                }
            }
            for (int i = 0; i < table.GetLength(0); i++)
            {
                for (int j = 0; j <=i; j++)
                {
                    Console.Write(table[i, j]+"  ");
                }
                Console.WriteLine(" ");

            }
                
         }
        static void Hollow()
        {
            Console.WriteLine("请输入正方形的边长！");
            int length = Convert.ToInt32(Console.ReadLine());

            string[,] arr = new string[length, length];

            for (int i = 0; i < length; i++)
            {
                for (int j = 0; j < length; j++)
                {
                    if (i==0||i== length-1|| j==0||j== length-1)
                    {
                        arr[i,j] = " * ";
                    }
                    else
                    {
                        arr[i, j] = "   ";
                    }
                }
            }

            for (int i = 0; i < length; i++)
            {
                for (int j = 0; j < length; j++)
                {
                    Console.Write(arr[i,j]);
                }
                Console.WriteLine(" ");
            }
        }
        static void rhombus()
        {
            //打印菱形                       
            //     *               边长为2，打印菱形的行数为3行
            //    ***              边长为3，打印菱形的行数为5行
            //   *****             边长为4，打印菱形的行数为7行
            //  *******               
            //   *****             总结出规律为：行数=边长数*2-1
            //    ***                 
            //     *           
            //                    

            //思路：打印菱形的行数为：（行数=边长数*2-1）
            //菱形行数一般是奇数，由三部分组成上下两个相等大小的三角形和一条中轴组成

            //Console.WriteLine("请输入菱形的边长！");
            //int length = Convert.ToInt32(Console.ReadLine());
            //int ID = length * 2 - 1;
            //string[,]  arr = new string[ID, ID];

            //for (int i = ID/2; i < length; i++)
            //{

            //}
            Console.WriteLine("输入一个大于2的正整数");//至少3行才能出一个菱形，输入一个偶数菱形就是这个偶数减1行
            int n = Convert.ToInt32(Console.ReadLine());
            for (int i = 1; i <= (n + 1) / 2; i++) //打印菱形的上面部分
            {
                for (int j = (n - 1) / 2; j >= i; j--)
                {    //打印空格
                    Console.Write(" ");
                }
                for (int k = 1; k <= i * 2 - 1; k++)
                {   //打印“*”号，第i行有i*2-1个“*”号
                    Console.Write("*");
                }
                Console.WriteLine();
            }
            for (int i = (n - 1) / 2; i >= 1; i--)//打印菱形下面的部分 与上面部分同理
            {
                for (int j = i - 1; j < (n - 1) / 2; j++)
                {
                    Console.Write(" ");
                }
                for (int k = 1; k <= i * 2 - 1; k++)
                {
                    Console.Write("*");
                }
                Console.WriteLine();
            }


        }
        //杨辉三角
        static void Tast5()
        {
            int[][] arr = new int[10][];
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                arr[i] = new int[i + 1];
            }
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j <= i; j++)
                {
                    if (i == 0 || j == 0)
                    {
                        arr[i][j] = 1;
                    }
                    else
                    {
                        //arr[i, j] =Convert.ToString(int.Parse(arr[i - 1, j]) + int.Parse(arr[i - 1, j - 1]));
                        if ((i == 2 && j == 2) || i == j)
                        {
                            arr[i][j] = 1;
                        }
                        else
                        {
                            arr[i][j] = arr[i - 1][j] + arr[i - 1][j - 1];
                        }
                    }
                }
            }

            for (int i = 0; i < arr.GetLength(0); i++)
            {
                foreach (int item in arr[i])
                {
                    Console.Write(item + " ");
                }
                Console.WriteLine();
            }


        }
        //数组练习1
        static void Tast6()
        {
            int[] arr = { 1, 2, 4, 5, 6 };
            Console.Write("数组中下标是偶数的元素有：");
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                if (i % 2 == 0)
                {
                    Console.Write(arr[i] + " ");
                }

            }
        }
        //数组练习2
        static void Tast7()
        {
            //如果一个数组保存元素是有序的（从大到小），
            //向这个数组中插入一个数，
            //使得插入后的数组元素仍然保持有序。
            int[] arr = { 10, 7, 4, 3 };
            int[] arr1 = new int[5];
            int temp = 0;
            Console.WriteLine("插入前的数组：");
            foreach (int item in arr)
            {
                Console.Write(item + " ");
            }
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                arr1[i] = arr[i];
            }

            Console.WriteLine();
            Console.WriteLine("请输入一个数：");
            arr1[4] = int.Parse(Console.ReadLine());
            Console.WriteLine("插入后的数组：");
            foreach (int item in arr1)
            {
                Console.Write(item + " ");
            }
            for (int i = 0; i < arr1.GetLength(0) - 1; i++)
            {
                for (int j = 0; j < arr1.GetLength(0) - 1 - i; j++)
                {
                    if (arr1[j] < arr1[j + 1])
                    {
                        temp = arr1[j];
                        arr1[j] = arr1[j + 1];
                        arr1[j + 1] = temp;

                    }
                }
            }
            Console.WriteLine("插入后的数组：");
            foreach (int item in arr1)
            {
                Console.Write(item + " ");
            }
        }


    }
}
